$(function(){
	// 日期
	var ul_data = $('.honorBox .ul_data li');
	$.each(ul_data, function(){
		if($(this).children("div").length == 1){
			$(this).addClass('hidden-xs')
		}
			
	});
	
	// 资质荣誉
	var urlList = location.href.split("?")[0].split("/").pop();
	if( urlList == 'qualification_honor.html'){
		var searchUrl = window.location.href;
		var ind = searchUrl.split("=")[1]; //截取 url中的“=”,获得“=”后面的参数
		// console.log(ind)
		$('.honor_nav li').eq(ind).addClass('pitch');
		$('.honorBox').eq(ind).css('display','block')
		businessGlory(0)  //资质荣誉
		// engineeringGlory() //工程获奖
		engineeringQualification() //资质资格
	}
	
	// if( urlList == 'project_show.html'){
	// 	var searchUrl = window.location.href;
	// 	var ind = searchUrl.split("=")[1]; //截取 url中的“=”,获得“=”后面的参数
	// 	console.log(ind)
		
	// }
})

var page = 1 ; //当前页
var size = 12 ; //当前页数据几条

//所以项目
function allProject(id,page) {
	$(".projectBox ul").empty()
	$.ajax({
		type: 'POST',
		url: urlBox+'/api/allProject/',
		data:{
			category_id: id,
			page: page,
			size: size,
		},
		dataType: 'json',
		success: function(res) {
			var list = res.project_list
			// console.log(list.length)
			if (list.length != 0) {
				for (var i = 0; i < list.length; i++) {
					var li = $('<li>'
									+'<a href="case_particulars.html?project_id='+list[i].project_id+'">'
										+'<div class="img">'
											+'<img src="'+urlBox+ list[i].banner_url +'" alt="">'
											+'<div class="examine">—  查看详情  —</div>'
										+'</div>'
										+'<div class="title">'+ list[i].project_name +'</div>'
									+'</a>'
								+'</li>')
					$(".projectBox ul").append(li);
				}
				// if(list != ''){
				// }
				$("#page").fadeIn()
				num_pagesBox(id,page,res.num_pages);
				$('.projectBox ul').removeClass('PC_height')
			}else{
				$("#page").fadeOut()
			}
		}
			
	})
}

// 项目展示导航
function projectNav(tihs,id){
	$('.project_nav li').removeClass('pitch')
	$(tihs).addClass('pitch');
	allProject(id,1)
	
	$(".projectBox ul li").fadeIn()
}

//分页

function num_pagesBox(id,page,num_pages){
	$("#page").paging({
		pageNum: page, // 当前页面
		totalNum: num_pages, // 总页码
		callback: function (num) { //回调函数
			$('.projectBox ul').addClass('PC_height')
			allProject(id,num)
		}
	});
}
//项目详情
function projectDetails(id) {
	$(".projectBox ul").empty()
	$.ajax({
		type: 'POST',
		url: urlBox+'/api/projectDetails/',
		data:{
			id: id
		},
		dataType: 'json',
		success: function(res) {
			var list = res.project_details
			var img_list = list.img_list
			// console.log(img_list.length)
			
			// $('.case_particulars_daoahng').text(' / ' + list.category_name +' / '+ list.project_name)
			$('.case_particulars_daoahng').text(' / '+ list.project_name)
			var div = $('<div class="case_show_top">'
							+'<h3>'+list.project_name+'</h3>'
							+'<div class="title">所属行业：'+list.category_name+'</div>'
							+list.article
						+'</div>')
			$(".case_show").prepend(div);	
			if(img_list.length != 0){
				for (var i = 0; i < img_list.length; i++){
				var divs = $('<div class="item">'+
					'<img class="hidden-xs" src="'+urlBox+img_list[i]+'" alt="...">'+
					'<img class="visible-xs-block" src="'+urlBox+img_list[i]+'" alt="">'+
				'</div>')
				var li = $('<li data-target="#carousel-example-generic" data-slide-to="1"></li>')
				$(".banner .carousel-inner").append(divs);
				$(".banner .carousel-indicators").append(li);
				
				}
				$('.banner .carousel-inner>div').eq(0).addClass('active')
				$('.banner .carousel-indicators>li').eq(0).addClass('active')
				
				var div = $('<a class="left carousel-control hidden-xs" href="#carousel-example-generic" role="button" data-slide="prev"><img src="img/pc/xiangmu/xiangmu_2_jiantou1.png" ></a><a class="right carousel-control hidden-xs" href="#carousel-example-generic" role="button" data-slide="next"><img src="img/pc/xiangmu/xiangmu_2_jiantou2.png" ></a>')
				$("#carousel-example-generic").append(div);
			}
		}
			
	})
}


// 资质荣誉导航
$('.honor_nav li').click(function(){
	$('.honor_nav li').removeClass('pitch')
	$(this).addClass('pitch');
	
	$('.honorBox').css('display','none')
	$('.honorBox').eq($(this).index()).css('display','block')
	
})

//资质荣誉
function businessGlory(k) {
	$(".honorBox .ul_nav").empty()
	$(".honorBox .ul_data").empty()
	$.ajax({
		type: 'GET',
		url: urlBox+'/api/businessGlory/',
		dataType: 'json',
		success: function(res) {
			var list = res.glory_list
			// console.log(list)
			for (var i = 0; i < list.length; i++) {
				var li = $('<li>'+list[i].name+'</li>')
				$(".honorBox .honorBoxName").append(li);
			}
				
			// for (var i = 0; i < list.length; i++) {
			// 	var li = $('<li onclick="timeNav(this,'+ i +')">'+list[i].time_quantum+'</li>')
			// 	$(".honorBox .ul_nav").append(li);
			// 	$('.honorBox .ul_nav li').eq(k).addClass('pitch');
			// }
			// var time_info = list[k].time_info
			// for (var j = 0; j < time_info.length; j++) {
			// 	var liData = $('<li id="'+j+'">'
			// 						+'<div class="title hidden-xs">'+time_info[j].last_time+'</div>'
			// 					+'</li>')
								
			// 	$(".honorBox .ul_data").append(liData);
				
			// 	var details = time_info[j].details
			// 	for (var r = 0; r < details.length; r++) {
			// 		var div = $('<div>'+details[r]+'</div>')
			// 		$(".honorBox .ul_data li#"+j).append(div);
			// 	}
			// }
			// $('.honorBox').removeClass('PC_height')
		}
			
	})
}

//年份导航
function timeNav(tihs,i){
	$('.honorBox').addClass('PC_height')
	// console.log(i)
	$('.honorBox li').removeClass('pitch')
	$(tihs).addClass('pitch');
	businessGlory(i)  //资质荣誉
}

//工程获奖
function engineeringGlory() {
	$(".projectHonor .project_honor").empty();
	$(".projectHonor p").empty();
	$(".projectHonor .visible-xs-block").empty();
	$.ajax({
		type: 'GET',
		url: urlBox+'/api/engineeringGlory/',
		dataType: 'json',
		success: function(res) {
			var list = res.glory_list
			// console.log(list)
			for (var i = 0; i < list.length; i++) {
				var li = $('<li data-details="'+list[i].details+'" onclick="bearNav(this)">'+list[i].name+'</li>')
				
				$(".projectHonor .project_honor").append(li);
				$('.projectHonor .project_honor li').eq(0).addClass('pitch');
				
				var div = $('<div>'
								+'<div>'+list[i].name+'</div>'
								+'<p>'+list[i].details+'</p>'
							+'</div>')
				$(".projectHonor .visible-xs-block").append(div);
					
			}
			$(".projectHonor p").append(list[0].details);
		}
			
	})
}

//工程获奖
function bearNav(that){
	$(".projectHonor p").empty();
	var details =$(that).data('details')
	$('.projectHonor li').removeClass('pitch')
	$(that).addClass('pitch');
	$(".projectHonor p").append(details);
}
	
//资质资格
function engineeringQualification() {
	$(".qualification").empty();
	// $(".box dl").empty();
	$(".YD_certificate").empty();
	$.ajax({
		type: 'GET',
		url: urlBox+'/api/engineeringQualification/',
		dataType: 'json',
		success: function(res) {
			var list = res.qualification_list
			// console.log(list)
			for (var i = 0; i < list.length; i++) {
				var div = $('<div>'
								+'<div>'+list[i].name+'</div>'
								+'<p>'+list[i].details+'</p>'
							+'</div>')
				var dd =$('<dd>'
								+'<div>'
									// +'<img src="img/pc/zizhi_tu2_hover.png" />'
									+'<img src="'+urlBox+list[i].img_url+'" />'
								+'</div>'
								+'<p>'+list[i].name+'</p>'
							+'</dd>')
				
				$(".qualification").append(div);
				$(".box dl").append(dd);
				
				var divs =$('<div>'
								+'<div>'
									// +'<img src="img/pc/zizhi_tu2_hover.png" />'
									+'<img src="'+urlBox+list[i].img_url+'" />'
								+'</div>'
								// +'<p>'+list[i].name+'</p>'
							+'</div>')
							
				$(".YD_certificate").append(divs);			
			}
				$(".box").superSlider({
					prevBtn: ".prev", //左按钮
					nextBtn: ".next", //右按钮
					listCont: "#roll", //滚动列表外层
					scrollWhere: "prev", //自动滚动方向next
					delayTime: 1000, //自动轮播时间间隔
					speed: 300, //滚动速度
					amount: 1, //单次滚动数量
					showNum: 2.9, //显示数量
					autoPlay: false //自动播放
				});
			// $(".projectHonor p").append(list[0].details);
		}
			
	})
}

